package GroupChats;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1",8888);
        //由该线程来负责接收信息
        new ClientThread(socket).start();

        //由主线程来负责输出信息
        //先获取到低级IO流
        OutputStream outputStream = socket.getOutputStream();
        //再进行打包成高级数据流
        DataOutputStream dos = new DataOutputStream(outputStream);

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入消息:");
            String msg = scanner.nextLine();
            if ("exit".equals(msg)){
                System.out.println("退出成功!!!");
                //退出后，关闭资源
                dos.close();
                socket.close();
                break;
            }
            dos.writeUTF(msg);
            //刷新
            dos.flush();
        }
    }

}
